﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LightPublisherCms.Data.Entities;
using System.Linq;

namespace LightPublisherCms.Tests.DataTests
{
    [TestClass]
    public class AuthorsTest
    {
        [TestMethod]
        public void TestCreate()
        {
            Author author = new Author()
            {
                Title = "Test Title",
                FirstName = "Test First Name",
                MiddleName = "Test Middle Name",
                LastName = "Test Last Name",
                Biography = "Test Biography",
                Email = "Test e-mail"
            };

            using (DataContext db = new DataContext())
            {
                db.Authors.Add(author);
                db.SaveChanges();

                Assert.AreNotEqual(0, author.AuthorId);

                Author authorSaved = (from a in db.Authors
                                      where
                                      a.AuthorId == author.AuthorId &&
                                          a.Title == "Test Title" &&
                                          a.FirstName == "Test First Name" &&
                                          a.MiddleName == "Test Middle Name" &&
                                          a.LastName == "Test Last Name" &&
                                          a.Biography == "Test Biography" &&
                                          a.Email == "Test e-mail"
                                      select a).First();
            }
        }

        [TestMethod]
        public void TestFullName()
        {
            Author author = new Author()
            {
                Title = "Test Title",
                FirstName = "Test First Name",
                MiddleName = "Test Middle Name",
                LastName = "Test Last Name",
                Biography = "Test Biography",
                Email = "Test e-mail"
            };

            Assert.AreEqual("Test Title Test First Name Test Middle Name Test Last Name", author.GetFullName());
        }

        [TestMethod]
        public void TestShortName()
        {
            Author author = new Author()
            {
                Title = "Test Title",
                FirstName = "Test First Name",
                MiddleName = "Test Middle Name",
                LastName = "Test Last Name",
                Biography = "Test Biography",
                Email = "Test e-mail"
            };

            Assert.AreEqual("Test First Name T.", author.GetFullName());
        }
    }
}
